package com.hx.petsever.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hx.petsever.entity.GoodAssess;
import com.hx.petsever.entity.Goods;
import com.hx.petsever.entity.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Orders> {

    @Select("SELECT a.id, a.name ,a.address ,a.phone , a.state ,a.goodname ,a.price ,a.number,a.goodid FROM orders a,user_order b  WHERE b.userid = #{id} AND  a.id = b.orderid AND a.state = #{state}")
    List<Orders> getOrderByState(@Param("id") String id , @Param("state") Integer state);

    @Insert("INSERT INTO orders SET id = #{id} , NAME = #{name} , address = #{address},phone = #{phone} ,state = #{state} , goodname = #{goodname} , price = #{price} , number = #{number} , goodid = #{goodid}")
    void InsertOne(@Param("id") String id , @Param("name") String name ,@Param("address")String address , @Param("phone") String phone ,@Param("state") Integer state, @Param("goodname") String goodname , @Param("price") String price,@Param("number") Integer number,@Param("goodid") Integer goodid );

    @Insert("INSERT INTO user_order SET userid = #{userid} , orderid = #{orderid}")
    void InsertRelation(@Param("userid") String userid ,@Param("orderid") String orderid);

    @Update("UPDATE orders SET  state = #{state} WHERE id = #{id}")
    void updateOrder(@Param("id") String id , @Param("state") Integer state);

    @Select("select * from orders where id = #{id}")
    Orders getOne(@Param("id") String id);

    @Select("select * from orders")
    List<Orders> getAll();

    @Insert("insert into order_reason set id = #{id}  , reason = #{reason}")
    void InsertReason(@Param("id") String id , @Param("reason") String reason);

    @Select("select reason from order_reason where id = #{id}")
    String getReason(@Param("id") String id);

    @Select("select userid from user_order where orderid = #{orderid}")
    String getUserid(@Param("orderid") String id);

    @Insert("insert into good_assess set goodid = #{goodid} , orderid = #{orderid} , userid = #{userid} , assess = #{assess}")
    void InsertAssess(@Param("goodid") Integer goodid , @Param("orderid") String orderid , @Param("userid") String userid , @Param("assess") String assess);

    @Select("select * from good_assess where orderid = #{orderid}")
    GoodAssess haveAssessByOrderId(@Param("orderid") String orderid);
}
